package Fragment;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import Database.SQLquery;
import Library.IntentIntegrator;
import ListView_Adapter.PersonList_Adapter;
import ListView_Adapter.Person_Detail;
import barcode.code.nhat.iuhbarcode.Main_Action;
import barcode.code.nhat.iuhbarcode.R;

public class Zxing_fragment extends Fragment {

    private static final String ARG_SECTION_NUMBER = "section_number";

    public static Zxing_fragment newInstance(int sectionNumber) {
        Zxing_fragment fragment = new Zxing_fragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }

    public Zxing_fragment() {
    }

    private ListView l1;
    private Button b1, b2, b3;
    private Spinner sp;
    public static int pos;
    private String[] Titles;

    public int getNum(){
        return pos;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View zx = inflater.inflate(R.layout.fragment_zxing, container, false);

        sp = (Spinner) zx.findViewById(R.id.spinner_period_zxing);
        Titles = getResources().getStringArray(R.array.period);
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, Titles);
        sp.setAdapter(dataAdapter);
        sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                pos = position + 1;
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        b1 = (Button) zx.findViewById(R.id.bt_scan_code);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentIntegrator love = new IntentIntegrator(getActivity());
                love.initiateScan();
            }
        });



        return zx;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        ((Main_Action) activity).onSectionAttached(getArguments().getInt(ARG_SECTION_NUMBER));
    }

}
